<?php
/********************************************************************
 *	Author:
 *		Jestery Liu <jestery@gmail.com>
 *		http://www.pte.cn
 *
 *	File:			Module.class.php
 *	Create Date:	2007-05-23 17:30:51 CST
 *******************************************************************/

class Module
{
	/**
	 * The request object
	 *
	 * @var HttpRequest
	 */
	protected $request;
	/**
	 * The response object
	 *
	 * @var HttpResponse
	 */
	protected $response;
	/**
	 * The dispatcher object
	 *
	 * @var Dispatcher
	 */
	protected $dispatcher;
	
	protected $container = array();
	
	public function __construct()
	{
	}
	
	public function setItem($name, $item) {
		$this->container[$name] = $item;
	}
	
	public function getItem($name) {
		if (array_key_exists($name, $this->container)) {
			return $this->container[$name];
		} else {
			return null;
		}
	}
	
	public function hasItem($name) {
		return array_key_exists($name, $this->container) && !empty($this->container[$name]);
	}
	
	public function setRequest($req)
	{
		$this->request = $req;
	}
	public function getRequest()
	{
		return $this->request;
	}
	public function setResponse($resp)
	{
		$this->response = $resp;
	}
	public function getResponse()
	{
		return $this->response;
	}
	public function setDispatcher($dispatcher)
	{
		$this->dispatcher = $dispatcher;
	}
	public function getDispatcher()
	{
		return $this->dispatcher;
	}
	protected function getParam($key, $default=null)
	{
		return $this->request->getParam($key, $default);
	}
	protected function getParmas()
	{
		return $this->request->getParams();
	}
	protected function getQuery($key, $default=null)
	{
		return $this->request->getQuery($key, $default);
	}
	protected function getPost($key, $default=null)
	{
		return $this->request->getPost($key, $default);
	}
	protected function getCookie($key, $default=null)
	{
		return $this->request->getCookie($key, $default);
	}
	protected function getEnv($key, $default=null)
	{
		return $this->request->getEnv($key, $default=null);
	}
	protected function getServer($key, $default=null)
	{
		return $this->request->getServer($key, $default);
	}
	protected function getMethod()
	{
		return $this->request->getMethod();
	}
	protected function isPost()
	{
		return $this->request->isPost();
	}
	protected function getHeader($header)
	{
		return $this->request->getHeader($header);
	}
	protected function isXmlHttpRequest()
	{
		return $this->request->isXmlHttpRequest();
	}
	protected function setNextAction($actionName, array $params = array())
	{
		$this->dispatcher->setNextAction($actionName, $params);
	}
}